package be.ac.ua.ecampus.uacmat.entity;

import java.sql.SQLException;
import java.util.Collection;
import java.util.HashSet;

import be.ac.ua.ecampus.uacmat.QueryHandler;

public class Packet extends Entity {

	private int fAcademicYear;
	private Collection<Syllabus> fSyllabuses;
	private String fProgram_id;
	private Program fProgram = null;
	private Collection<String> fCampuses = null;
	
	public Packet(String id, String description, int academicYear, String program_id) throws SQLException {
		super("packet", id, description);
		this.fAcademicYear = academicYear;
		this.fSyllabuses = new HashSet<Syllabus>();
		this.fCampuses = new HashSet<String>();
		this.fProgram_id = program_id;
	}
	
	public Program getProgram() throws SQLException {
    	if (fProgram == null) {
    		QueryHandler queryHandler = new QueryHandler();
    		fProgram = queryHandler.getProgram(fProgram_id);
    	}
    	if (fProgram == null) {
    		fProgram = new Program("", "No program available.","");
    	}
    	return fProgram;
    }

	public int getAcademicYear() {
		return fAcademicYear;
	}

	public Collection<Syllabus> getSyllabuses() throws SQLException {
		if (fSyllabuses.isEmpty()) {
			QueryHandler queryHandler = new QueryHandler();
			fSyllabuses = queryHandler.getSyllabusesForPacket(this.fId);
		}
		return fSyllabuses;
	}
	
	public Collection<String> getCampuses() throws SQLException {
    	if (fCampuses.isEmpty()) {
    		QueryHandler queryHandler = new QueryHandler();
    		fCampuses = queryHandler.getCampusesForPacket(this.fId);
    	}
    	return fCampuses;
    }
}
